package com.xj.business.airc.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ie.api.center.data.fegin.RealDataClient;
import com.xj.business.airc.bean.constant.Common;
import com.xj.business.airc.service.PHomepageService;
import com.xj.common.bean.Pages;
import com.xj.common.bean.R;
import com.xj.common.bean.point.PointValue;
import com.xj.common.dto.PointValueDto;
import com.xj.common.model.Device;
import com.xj.common.utils.JsonPaseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 实时数据接口
 * @author wsp
 *
 */
@RestController
@RequestMapping(value = Common.Service.IE_BUS_AIRC_HOMEPAGE)
public class PHomepageAPI  {


	@Resource
	PHomepageService pHomepageService;
	/**
	 * 通过设备id获取该设备的所有实时数据
	 * @param jsonParam
	 * @return
	 */
	@RequestMapping(value = Common.Service.IE_BUS_AIRC_HOMEPAGE_GETALL,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@CrossOrigin
	public R<Map<String ,String >> GetAllByTenantid(
			@RequestBody JSONObject jsonParam)
	{
		Long tenantId = jsonParam.getLong("tenantId");
		Boolean history = jsonParam.getBoolean("history");
		Map<String ,String > result = pHomepageService.GetAllByTenantid(tenantId,history);
		if(result!=null){
			return R.ok(result,"OK");
		}
		return R.fail();
		
	}

	/**
	 * 通过设备id获取该设备的所有实时数据
	 * @param jsonParam
	 * @return
	 */
	@RequestMapping(value = Common.Service.IE_BUS_AIRC_HOMEPAGE_GETALLDEVICE,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@CrossOrigin
	public R<List<Map<String,Object>>> GetDevicesByTenantid(
			@RequestBody JSONObject jsonParam)
	{
		Long tenantId = jsonParam.getLong("tenantId");
		List<Map<String,Object>> result = pHomepageService.GetAllDeviceByTenantid(tenantId);
		if(result!=null){
			return R.ok(result,"OK");
		}
		return R.fail();

	}


}
